package com.dynamo.transport.network.practise.channel;

/**
 * @author duanyimiao
 * @create 2018-11-17 9:58 PM
 * @description
 **/
public class SimpleChannelHandler implements ChannelUpstreamHandler, ChannelDownstreamHandler {
    @Override
    public void handleDownstream(ChannelHandlerContext ctx, ChannelEvent e) {
        System.out.println("SimpleChannelHandler handleDownstream");
        ctx.sendDownstream(e);
    }

    @Override
    public void handleUpstream(ChannelHandlerContext ctx, ChannelEvent e) {

        if (e instanceof MessageEvent) {

            messageReceived(ctx, (MessageEvent) e);
        }

    }

    /**
     * 模板模式，由子类重写
     *
     * @param ctx
     * @param e
     */
    public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) {
        ctx.sendUpstream(e);
    }

}
